package com.dykj.fireFighting.web.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import com.dykj.fireFighting.api.elasticsearch.devHis.entity.EsDevHis;
import com.dykj.fireFighting.api.elasticsearch.devHis.service.EsDevHisService;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.model.report.DevHis;
import com.dykj.fireFighting.web.rocketmq.message.InsertDevHisMessage;
import com.dykj.fireFighting.web.service.DevHisService;
import com.dykj.fireFighting.web.utils.SpringUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhengbo
 */
//@RocketMQMessageListener(
//        topic = InsertDevHisMessage.TOPIC,
//        consumerGroup = "dy-consumer-group-" + InsertDevHisMessage.TOPIC
//)
public class InsertDevHisConsumer implements RocketMQListener<InsertDevHisMessage> {
   public static final Logger LOGGER = LoggerFactory.getLogger(InsertDevHisConsumer.class);
    private static final RedisService redisService= SpringUtil.getBean(RedisService.class);
    private static final DevHisService devHisService= SpringUtil.getBean(DevHisService.class);
    private static final EsDevHisService esDevHisService= SpringUtil.getBean("esDevHisService");
    @Override
    public void onMessage(InsertDevHisMessage insertDevHisMessage) {
//        DevHis devHis = insertDevHisMessage.getDevHis();
//        LOGGER.info("===========插入devHis数据到mysql==============");
//        devHisService.insertHis(devHis);
//        LOGGER.info("===========插入EsDevHis数据到ES==============");
//        EsDevHis esDevHis = new EsDevHis();
//        BeanUtils.copyProperties(devHis, esDevHis);
//        esDevHis.setUnitId(devHis.getUnitsCode());
//        esDevHis.setDeviceName(devHis.getDevName());
//        esDevHis = esDevHisService.importAll(esDevHis);
//        LOGGER.info("===========插入EsDevHis数据到ES:=============" + JSON.toJSONString(esDevHis));
//
//        redisService.set(devHis.getId(), JSON.toJSONString(devHis), 3600L);
    }
}
